﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Utilities
{
    public class FileUtils
    {
        /****************************************************************
         * 
         * 只砍掉該目錄下的檔案
         * 不會把目錄也砍了
         * 
         * ***************************************************************/
        public static void DeleteSubFilesOnly(String path)
        {
            if (Directory.Exists(path) == false)
                return;
            string[] dirs = Directory.GetDirectories(path);
            foreach (String dir in dirs)
            {
                Directory.Delete(dir);
            }
            string[] subFiles = Directory.GetFiles(path);
            foreach (String file in subFiles)
            {
                File.Delete(file);
            }
        }
        public static bool deleteFile(String fileName)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            return true;
        }


        public static void saveUTF8(string fileName, string content)
        {
            deleteFile(fileName);
            String p=Path.GetDirectoryName(fileName);
            if (Directory.Exists(p) == false)
                Directory.CreateDirectory(p);
            File.WriteAllText(fileName, content,Encoding.GetEncoding("utf-8"));
        }
    }
}
